<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
            <el-form-item label="流水类型" prop="flowType">
                <el-select v-model="queryParams.flowType" placeholder="流水类型" clearable style="width: 200px">
                    <el-option v-for="dict in flow_type" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="操作类型" prop="actionType">
                <el-select v-model="queryParams.actionType" placeholder="操作类型" clearable style="width: 200px">
                    <el-option v-for="dict in action_type" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getLogList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="logList">
            <el-table-column label="流水类型" align="center" prop="flowType">
                <template #default="scope">
                    <dict-tag :options="flow_type" :value="scope.row.flowType" />
                </template>
            </el-table-column>
            <el-table-column label="操作类型" align="center" prop="actionType">
                <template #default="scope">
                    <dict-tag :options="action_type" :value="scope.row.actionType" />
                </template>
            </el-table-column>
            <el-table-column label="金额" align="center" prop="amount">
                <template #default="scope">
                    <span>{{ scope.row.amount / 100 || 0 }}</span>
                </template>
            </el-table-column>
            <el-table-column label="创建时间" align="center" prop="createTime">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize" @pagination="getLogList" />
    </div>
</template>

<script setup name="WalletLog">
import { walletLogList } from "@/api/subject/wallet";
const { proxy } = getCurrentInstance();
const { flow_type, action_type } = proxy.useDict("flow_type", "action_type");
const loading = ref(true);
const showSearch = ref(true);
const logList = ref([])
const total = ref(0);

const data = reactive({
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        flowType: undefined,
        actionType: undefined,
    },
});

const { queryParams } = toRefs(data);
function getLogList() {
    loading.value = true
    walletLogList(queryParams.value).then((response) => {
        loading.value = false
        logList.value = response.rows;
        total.value = response.total;
    })
}
/** 搜索按钮操作 */
function handleQuery() {
    getLogList();
}
/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
}
getLogList()
</script>